<template>
  <div class="changeinfo">
    <NavBar title="修改联系人信息" left-arrow @click-left="returnAdd()" />
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="name"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="sex"
        name="sex"
        label="性别"
        placeholder="性别"
        :rules="[{ pattern: /1||2/, required: true, message: '请填写性别' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>
  </div>
</template>
<script>
import { NavBar } from "vant";
import { userUpdateApi } from "../utils/api";
export default {
  data() {
    return {
      username: "",
      password: "",
      pattern: /1||2/,
    };
  },
  components: {
    NavBar,
  },
  methods: {
    returnAdd() {
      this.$router.push("/userinfo");
    },
    onSubmit(values) {
      console.log("submit", values);
      console.log(this.token);
      console.log(values.name);
      console.log(values.sex);
      userUpdateApi({
        token: this.token,
        nickName: values.name,
        sex: values.sex,
      }).then((res) => {
        console.log(res);
      });
    //   this.$router.push("/userInfo");
    },
  },
};
</script>
<style scoped>
/* 标题 */
.changeinfo /deep/ .van-ellipsis {
  font-size: 18px;
  font-weight: 700;
}
/* 返回箭头 */

.changeinfo /deep/ .van-icon-arrow-left {
  color: black;
  font-size: 24px;
  font-weight: 700;
}
</style>